$(function() {
        	
	var service = new EbeimService();
	var device = "";
	
	$("#j-reset").click(function(){
		$("#username").val("");
		$("#password").val("");
	});
	
	service.getComputerMessage(function(json){
		if(json.code == 200) {
			device = json.bindDevice;
		}else{
            alert(json.desc);
        }
	});
	
	var callback = function(data) {
		var json = eval("(" + data + ")");
		if(json.code == "200"){
			if(json.user.isUpdateDefaultPwd == "0"){
				window.location.href = "../html/noIntercept/activate.html?userId="+json.user.id + "&username=" + json.user.username+"&phone="+json.user.mobile;
			}else{
				if(json.user.isFirstLogin == "0" && json.user.labType != "0"){
					if(json.user.labType == "3" || json.user.labType == "4"){
						window.location.href = "../html/noIntercept/binding.html?labType="+json.user.labType + "&username=" + json.user.username;
					}else{
						window.location.href = "../html/noIntercept/unBinding.html?labType="+json.user.labType + "&username=" + json.user.username;
					}
				}else{
					if(device != json.user.bindDevice && json.user.bindDevice != null){
						window.location.href = "../html/noIntercept/noWay.html";
					}else{
						if(json.overCapacitystatus != ""){
							alert(json.overCapacitydesc);
						}
						if(json.overAutuTimestatus != ""){
							alert(json.overAutuTimedesc);
						}
						window.location.href = "../index.html";
					}
				}
			}
		}else{
			alert(json.message);
		}
	};
	
   $('#j-submit').click(function() {
       var user = {
           username: $('#username').val(),
           password: $('#password').val()
       };
       if (user.username.length == 0 || user.password.length == 0) {
           alert("用户名或密码不能为空。");
           return;
       }
       service.login(user, callback);
   });
   
   $('#password').bind('keyup', function(event) {
       if (event.keyCode == "13") {
    	   var user = {
               username: $('#username').val(),
               password: $('#password').val()
           };
           if (user.username.length == 0 || user.password.length == 0) {
               alert("用户名或密码不能为空。");
               return;
           }
    	   service.login(user, callback);
       }
   });
});
